package com.gitee.huanminabc;

public class AccountingFlowEntityBuilder {

    private AccountingFlowEntityBuilder() {
    }

    public static Builder1 builder1(String accountNo, String accountName) {
        AccountingFlow accountingFlow = new AccountingFlow();
        accountingFlow.setAccountNo(accountNo);
        accountingFlow.setAccountName(accountName);
        return new Builder1(accountingFlow);
    }

    public static Builder2 builder2(String accountNo, String accountName, String transOrderNo) {
        AccountingFlow accountingFlow = new AccountingFlow();
        accountingFlow.setAccountNo(accountNo);
        accountingFlow.setAccountName(accountName);
        accountingFlow.setTransOrderNo(transOrderNo);
        return new Builder2(accountingFlow);
    }

    public static abstract class Builder {
        protected final AccountingFlow accountingFlow;
        private Builder(AccountingFlow accountingFlow) {
            this.accountingFlow = accountingFlow;
        }

        public AccountingFlow build() {
            return this.accountingFlow;
        }
    }


    public static class Builder1 extends Builder {
        private Builder1(AccountingFlow accountingFlow) {
            super(accountingFlow);
        }

        //可选
        public  Builder setAccountingDesc(String accountingDesc) {
            this.accountingFlow.setAccountingDesc(accountingDesc);
            return this;
        }

    }


    public static class Builder2 extends Builder {
        private Builder2(AccountingFlow accountingFlow) {
            super(accountingFlow);
        }
        //可选
        public  Builder setMemo(String memo) {
            this.accountingFlow.setMemo(memo);
            return this;
        }
    }


    public static void main(String[] args) {
        AccountingFlow build = AccountingFlowEntityBuilder.builder1("123", "test")
                .setAccountingDesc("desc")
                .build();

        AccountingFlow build1 = AccountingFlowEntityBuilder.builder2("123", "test", "orderNo")
                .setMemo("memo")
                .build();
    }

}